$(function() {

    if (window.location.host.indexOf("wawa") != -1) {
        document.domain = "wawa.fm";
    }

    $('.sidebar-collapse').sideNav({
        edge: 'left', // Choose the horizontal origin    
    });

    $('.menu-sidebar-collapse').sideNav({
        menuWidth: 240,
        edge: 'left', // Choose the horizontal origin     
        //defaultOpen:true // Set if default menu open is true
    });

    $('.dropdown-menu').dropdown({
        inDuration: 300,
        outDuration: 225,
        constrain_width: false, // Does not change width of dropdown to that of the activator
        hover: true, // Activate on hover
        gutter: 0, // Spacing from edge
        belowOrigin: true // Displays dropdown below the button
    });

    $('.header-search-input').focus(function() {
        $(this).parent('div').addClass('header-search-wrapper-focus');
    }).blur(function() {
        $(this).parent('div').removeClass('header-search-wrapper-focus');
    });

    function toggleFullScreen() {
        if ((document.fullScreenElement && document.fullScreenElement !== null) || (!document.mozFullScreen && !document.webkitIsFullScreen)) {
            if (document.documentElement.requestFullScreen) {
                document.documentElement.requestFullScreen();
            } else if (document.documentElement.mozRequestFullScreen) {
                document.documentElement.mozRequestFullScreen();
            } else if (document.documentElement.webkitRequestFullScreen) {
                document.documentElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
            }
        } else {
            if (document.cancelFullScreen) {
                document.cancelFullScreen();
            } else if (document.mozCancelFullScreen) {
                document.mozCancelFullScreen();
            } else if (document.webkitCancelFullScreen) {
                document.webkitCancelFullScreen();
            }
        }
    }

   // $('.tab-ul').tabs();
    //$('.tab-demo-active').show().tabs();

    $('.toggle-fullscreen').click(function() {
        toggleFullScreen();
    });

    $('.parallax').parallax();
    $('.modal-trigger').leanModal();
     

    $('select').not('.disabled').material_select();
    var leftnav = $(".page-topbar").height();
    var leftnavHeight = window.innerHeight - leftnav;
    $('.leftside-navigation').height(leftnavHeight).perfectScrollbar({
        suppressScrollX: true
    });

    var righttnav = $("#chat-out").height();
    $('.rightside-navigation').height(righttnav).perfectScrollbar({
        suppressScrollX: true
    });

    function is_touch_device() {
        try {
            document.createEvent("TouchEvent");
            return true;
        } catch (e) {
            return false;
        }
    }
    if (is_touch_device()) {
        $('#nav-mobile').css({
            overflow: 'auto'
        })
    }


    $('.datepicker').pickadate({
        selectMonths: true, // Creates a dropdown to control month
        selectYears: 15, // Creates a dropdown of 15 years to control year
        format: "yyyy-mm-dd"
    });

    $("#chk_all").on("click", function() {
        var b = $(this).prop("checked");
        $("input[name='checklist']").prop("checked", b);
        $(".checkbtn").prop("disabled", !b);
    })


    $(".checkipt").on("click", function(){
        var checked = $("input.checkipt:checkbox:checked").length;
        var checkbtn = $(".checkbtn");
        if(checked>0){
            checkbtn.prop("disabled", false);
        }else{
             $("#chk_all").prop("checked",false); 
            checkbtn.prop("disabled", true);
        }
    })

    $(".layer-close").on("click", function(){
    	if(!$(this).hasClass('loading')){
	    	$(".layer").css("display","none");
	    	$(".preview_modal").removeClass('pop');
    	}else{
    		return false;
    	}
    })


})

